import { Exclude } from 'class-transformer';
import { CommonEntity } from '../../../../common/entities/common.entity';
import { Role } from '../../role/entities/role.entity';
import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';

@Entity({
  name: 'sys_admin',
  comment: '系统-后台管理员',
})
export class Admin extends CommonEntity {
  @Column({
    type: 'varchar',
    length: 100,
    comment: '用户名',
    name: 'username',
  })
  username: string;

  @Column({
    type: 'varchar',
    length: 100,
    comment: '邮箱',
    name: 'email',
  })
  email: string;

  @Exclude()
  @Column({
    type: 'varchar',
    length: 100,
    comment: '密码',
    name: 'password',
  })
  password: string;

  @ManyToMany(() => Role, {
    createForeignKeyConstraints: false,
  })
  @JoinTable({
    name: 'ref_sys_admin_sys_role',
    joinColumn: {
      name: 'sys_admin_id',
    },
    inverseJoinColumn: {
      name: 'sys_role_id',
    },
  })
  roles?: Role[];
}
